﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Data;
using RBOSS.Utilities;
using System.Data.Entity;

namespace RBOSS.Business.AdminModule
{
    public class Roles_sys
    {
        public int RoleId;
        public string RoleName;
        public string Description;
       
        
        private RBOSSEntities rb = new RBOSSEntities();
        public Dictionary<string, string> getRoles()
        {
            Dictionary<string, string> d = new Dictionary<string, string>();

            var obj = rb.Roles.Where(e=>e.RoleId !=5).Select(e => new { e.RoleName, e.RoleId });
            foreach (var item in obj)
            {
                d.Add(item.RoleId.ToString(), item.RoleName);

            }

            return d;
        }
        public Roles_sys getselectedRoles(int Roleid)
        {
            Roles_sys r = new Roles_sys();
            var query = rb.Roles.Where(e => e.RoleId == Roleid).Select(e => new { e.RoleName, e.RoleId,e.Description}).FirstOrDefault();
            r.RoleId = query.RoleId;
            r.RoleName = query.RoleName;
            r.Description = query.Description;
            

            return r;
        }
        public void AddRole(string rolename,string roledes)
        {
            var role = new Role
            {
                RoleName=rolename,Description=roledes,
            RoleId=rb.Roles.Max(e=>e.RoleId) + 1 ,
               
            };
           
            rb.Roles.Add(role);
            rb.SaveChanges();
        }
        public void editrole(int roleid,string rolename, string roledes)
        {
            var role = new Role
            {
                RoleName = rolename,
                Description = roledes,
                RoleId = roleid,

            };
         
            rb.Entry(role).State = EntityState.Modified;
            rb.SaveChanges();
        }
    }
}
